from flask_appbuilder import Model
from sqlalchemy import BigInteger, Column, Integer, SmallInteger, String, Text

from myapp.models.base import MyappModelBase
from myapp.models.helpers import AuditMixinNullable


metadata = Model.metadata


class AutoLearning(Model, AuditMixinNullable, MyappModelBase):
    __tablename__ = 'auto_learning'
    # Defines the primary key column for the table. BigInteger supports a larger range of IDs.
    id = Column(BigInteger, primary_key=True)
    # Defines a column for the name of the auto-learning task.
    task_name = Column(String(200), nullable=False, default='', comment='任务名称')
    # Defines a column for the sub-dimension or category of the task.
    task_sub_dimension = Column(String(100), nullable=False, default='', comment='任务类型')
    # Defines a column for the specific type of the task within its sub-dimension.
    task_type = Column(String(100), nullable=False, default='', comment='任务子类型')
    # Defines a column for the ID of the primary dataset used.
    dataset_id = Column(Integer, nullable=False, default=0, comment='数据集id')
    # Defines a column to store a list of dataset IDs, likely as a comma-separated string.
    dataset_ids = Column(String(200), nullable=True, comment='数据集id列表')
    # Defines a column for the ID of an associated data labeling task.
    label_task_id = Column(Integer, nullable=False, default=0, comment='标注任务id')
    # Defines a column for the ID of an associated training job.
    training_job_id = Column(Integer, nullable=False, default=0, comment='训练任务id')
    # Defines a column for the ID of an associated inference service.
    infer_service_id = Column(BigInteger, nullable=False, default=0, comment='推理服务id')
    # Defines a soft-delete flag. A value of 1 (or non-zero) typically means the record is deleted.
    is_deleted = Column(SmallInteger, nullable=False, default=0, comment='是否删除')
    # Defines a column to store task-specific configurations, likely in JSON or YAML format.
    config = Column(Text, nullable=False, default='', comment='配置')
    # Defines a column to store configurations related to pre-training.
    pretrain_config = Column(Text, nullable=False, default='', comment='预训练配置')
    # Defines a column for the ID of the dataset used for testing/evaluation.
    test_dataset_id = Column(Integer, nullable=False, default=0, comment='测试数据集id')
    # Defines a column to categorize the task, e.g., standard automated learning vs. large model fine-tuning.
    task_category = Column(
        Integer,
        nullable=False,
        server_default='1',
        default=1,
        comment='类别：1、自动学习，2、大模型微调',
    )
    # Defines a column for the region, useful in multi-region deployments.
    region = Column(String(100), nullable=False, default='default', server_default='default', comment='地区')

    def __repr__(self):
        return self.id
